<?php
/**
 * Description of BookmarkableListener
 *
 * @author andy
 */
class BookmarkableFilter extends Doctrine_Record_Filter
{
  protected $_options = array(
  );

  public function __construct(array $options = array())
  {
    $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
  }

  public function init()
  {
  }

  public function filterSet(Doctrine_Record $record, $name, $value)
  {
    if ($name == $this->_options['relation_name'])
    {
      throw new LogicException('This property is read-only', 'readonly');
    }
  }

  public function filterGet(Doctrine_Record $record, $name)
  {
    if ($name == $this->_options['relation_name'])
    {
      return Doctrine::getTable($this->_options['component_name'])->createQuery('b')->where('b.model_component_name = ? AND b.model_id = ?',
        array($this->_table->getComponentName(), $record->get($this->_options['model_pk_name'])))->execute();
    }
  }
}
